﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections;

namespace UITLibraryManagement.Utilities
{
    /// <summary>
    /// Interaction logic for CategoryListControl.xaml
    /// </summary>
    public partial class CategoryListControl : UserControl, INotifyPropertyChanged
    {
        public static readonly DependencyProperty ItemFontSizeProperty = DependencyProperty.RegisterAttached
            ("ItemFontSize", typeof(double), typeof(CategoryListControl), new PropertyMetadata() { DefaultValue = 9.0 });
        public static readonly DependencyProperty ImagePathProperty = DependencyProperty.RegisterAttached
            ("ImagePath", typeof(ImageSource), typeof(CategoryListControl), new PropertyMetadata());
        public static readonly DependencyProperty ColorMouseOverProperty = DependencyProperty.RegisterAttached
            ("ColorMouseOver", typeof(Color), typeof(CategoryListControl), new PropertyMetadata() { DefaultValue = Colors.Blue });
        public static readonly DependencyProperty MyItemsSourceProperty = DependencyProperty.RegisterAttached
            ("MyItemsSource", typeof(IEnumerable), typeof(CategoryListControl), new PropertyMetadata(null));




        public CategoryListControl()
        {
            InitializeComponent();

            String text = ColorMouseOver.ToString();
        }

        public event PropertyChangedEventHandler PropertyChanged;


        public IEnumerable MyItemsSource
        {
            get { return (IEnumerable)GetValue(MyItemsSourceProperty); }
            set
            {
                List<String> strLst = value as List<String>;
                var itemsfff = value.GetEnumerator();
                itemsfff.Reset();
                String text = itemsfff.GetType().ToString();
                String type = "System.Collections.Generic.List`1+Enumerator[System.String]";
                if (text == type)
                {
                    string s = "";
                }
                if (strLst != null)
                {
                    List<ListBoxItem> lstItem = new List<ListBoxItem>();
                    for (int i = 0; i < strLst.Count; i++)
                    {
                        ListBoxItem item = new ListBoxItem();
                        item.Content = strLst[i];
                        item.Name = "Item" + i;
                        lstItem.Add(item);
                    }
                    SetValue(MyItemsSourceProperty, lstItem);
                }
                else
                    SetValue(MyItemsSourceProperty, value);
            }
        }

        public double ItemFontSize
        {
            get { return (double)GetValue(ItemFontSizeProperty); }
            set { SetValue(ItemFontSizeProperty, value); }
        }

        public ImageSource ImagePath
        {
            get { return (ImageSource)GetValue(ImagePathProperty); }
            set { SetValue(ImagePathProperty, value); }
        }

        public Color ColorMouseOver
        {
            get { return (Color)GetValue(ColorMouseOverProperty); }
            set
            {
                if (ColorMouseOver != value)
                {
                    SetValue(ColorMouseOverProperty, value);
                    OnPropertyChanged("ColorMouseOver");
                }
            }
        }
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged == null) return;
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public delegate void MyCategoryList_MouseLeftButtonDownHandler(object sender, MouseButtonEventArgs e);
        public event MyCategoryList_MouseLeftButtonDownHandler MyMouseLeftButtonDown;

        private void ListBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (MyMouseLeftButtonDown != null)
            {
                MyMouseLeftButtonDown(sender, e);
            }
        }
    }
}
